package com.cppsu.cgx.libraryseatselection.controller;

import com.cppsu.cgx.libraryseatselection.common.api.CommonResult;
import com.cppsu.cgx.libraryseatselection.dto.TipOffsParam;
import com.cppsu.cgx.libraryseatselection.dto.UserParam;
import com.cppsu.cgx.libraryseatselection.entity.TipOffs;
import com.cppsu.cgx.libraryseatselection.services.TipOffsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: guibo
 * @Description:
 * @Date: Created in 16:35 2021/3/15
 * @Modified By:
 */
@Controller
@Api(tags = "举报管理")
@RequestMapping("/tip-offs")
@CrossOrigin(origins = "*",maxAge = 3600)
public class TipOffsController {
    @Autowired
    TipOffsService tipOffsService;

    @ApiOperation("举报")
    @PostMapping(value = "/add")
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('admin','user')")
    CommonResult<Integer> add(TipOffsParam tipOffsParam){
        return CommonResult.success(tipOffsService.add(tipOffsParam));
    }
    @ApiOperation("批量删除")
    @PostMapping(value = "/delete")
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('admin','user')")
    CommonResult<Integer> delete(@RequestParam(value = "ids") List<Long> ids){
        return CommonResult.success(tipOffsService.delete(ids));
    }

    @ApiOperation("举报记录列表")
    @GetMapping(value = "/listByCurrentUser")
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('user')")
    CommonResult<List<TipOffs>> listByCurrentUser(){
        return CommonResult.success(tipOffsService.listByCurrentUser());
    }
}
